public class Offer_27 {
    /**
     * 剑指 Offer 27. 二叉树的镜像
     * 请完成一个函数，输入一个二叉树，该函数输出它的镜像。
     * 例如输入：
     *      4
     *    /   \
     *   2     7
     *  / \   / \
     * 1   3 6   9
     * 镜像输出：
     *
     *      4
     *    /   \
     *   7     2
     *  / \   / \
     * 9   6 3   1
     */
    public static TreeNode mirrorTree(TreeNode root) {
        if(root==null){
            return null;
        }
        TreeNode tempNode = null;
        tempNode = root.left;
        root.left = mirrorTree(root.right);
        root.right = mirrorTree(tempNode);
        return root;
    }

    public static void main(String[] args) {
        TreeNode treeNode1 = new TreeNode(4);
        TreeNode treeNode2 = new TreeNode(2);
        TreeNode treeNode3 = new TreeNode(7);

        TreeNode treeNode4 = new TreeNode(1);
        TreeNode treeNode5 = new TreeNode(3);

        TreeNode treeNode6 = new TreeNode(6);
        TreeNode treeNode7 = new TreeNode(9);
        treeNode1.left = treeNode2;
        treeNode1.right = treeNode3;

//        treeNode2.left = treeNode4;
//        treeNode2.right = treeNode5;

//        treeNode3.left = treeNode6;
//        treeNode3.right = treeNode7;

        System.out.println(mirrorTree(treeNode1));
    }
}
